package com.wj.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wj.dao.CheckItemDao;
import com.wj.entity.QueryPageBean;
import com.wj.pojo.CheckGroup;
import com.wj.pojo.CheckItem;
import com.wj.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author: WangJin
 * @description
 * @date: 2021/9/12 21:59
 */
@Service(interfaceClass = CheckItemService.class)
@Transactional
public class CheckItemServiceImpl extends ServiceImpl<CheckItemDao,CheckItem> implements CheckItemService {

    @Autowired
    private CheckItemDao checkItemDao;

    @Override
    public void add(CheckItem checkItem) {

        checkItemDao.add(checkItem);
    }

    @Override
    public Page<CheckItem> queryForPage(Page<CheckItem> page, String queryString) {

        Page<CheckItem> checkItemPage = checkItemDao.queryForPage(page, queryString);
        return checkItemPage;
    }


    public void deleteById(Integer id) {
        //查询当前检查项是否和检查组关联
        long count = checkItemDao.findCountByCheckItemId(id);
        if(count > 0){
            //当前检查项被引用，不能删除
            throw new RuntimeException("当前检查项被引用，不能删除");
        }
        checkItemDao.deleteById(id);
    }

    public CheckItem findById(Integer id) {
        return checkItemDao.findById(id);
    }

    @Override
    public List<CheckItem> findAll() {
        return checkItemDao.selectList(null);
    }



//    public void edit(CheckItem checkItem) {
//        checkItemDao.edit(checkItem);
//    }

}
